<!DOCTYPE html>
<html lang="zh">
{include file="public/head"}
<link rel="stylesheet" type="text/css" href="/static/admin/js/webuploader/webuploader.css">
<body>
<div class="container-fluid">
  
  <div class="row">
    
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">
          
          <form class="row" id="common_form" action="{$action}" method="post">
            <div class="mb-3 col-md-8">
              <label for="title" class="form-label">文章标题：</label>
              <input type="text" class="form-control" id="title" name="title" value="" placeholder="请输入文章标题" />
            </div>
            <div class="mb-3 col-md-12">
              <label for="username" class="form-label">文章封面:</label>
              <div class="d-flex">
                <img src="/no_image.jpg" class="me-3 show_upload_file" style="width: 240px;height: 240px">
                <input type="hidden" name="cover_img" class="file_path_value" value="/no_image.jpg">
                <div>
                  <div class="filePicker">上传图片</div>
                  <button type="button" class="btn btn-success" onclick="openLayer('选择图片', '/admin/common/selectImage',100,100)">选择图片</button>
                </div>
              </div>
            </div>
            
            <div class="mb-3 col-md-8">
              <label for="source" class="form-label">文章来源：</label>
              <input type="text" class="form-control" id="source" name="source" value="" placeholder="请输入文章来源"  />
            </div>
            <div class="mb-3 col-md-12">
              <label for="source" class="form-label">所属标签</label>
              <div class="col-sm-8">
                <select name="tag_id" class="form-select">
                  <option value="">请选择</option>
                  {volist name="tag" id="v1"}
                  <option value="{$v1.id}" disabled>{$v1.name}</option>
                    {volist name="v1.second" id="v2"}
                    <option value="{$v2.id}">&nbsp;├ {$v2.name}</option>
                    {/volist}
                  {/volist}
                </select>
              </div>
            </div>
            <div class="mb-3 col-md-12">
              <label for="source" class="form-label">文章分类：</label>
              <div class="col-sm-8">
                <select name="category_id" class="form-select">
                  <option value="">请选择</option>
                  <option value="1">重要霉</option>
                  <option value="2">文献</option>
                  <option value="3">工艺</option>
                </select>
              </div>
            </div>
            <div class="mb-3 col-md-12">
              <label for="source" class="form-label">文章简介：</label>
              <div class="col-sm-8">
                <textarea class="form-control" name="profile"></textarea>
              </div>
            </div>
            <div class="mb-3 col-md-12">
              <label for="source" class="form-label">文章内容：</label>
              <div class="col-sm-8" id="content">
                
              </div>
            </div>

            <div class="mb-3 col-md-8">
              <label for="sort" class="form-label">显示排序：</label>
              <input type="text" class="form-control" id="sort" name="sort" value="99" placeholder="请输入显示排序"  />
            </div>

            <div class="mb-3 col-md-8">
              <label for="浏览次数" class="form-label">浏览次数：</label>
              <input type="text" class="form-control" id="views" name="views" value="0" placeholder="请输入浏览次数"  />
            </div>

            <div class="mb-3 col-md-12">
              <label for="is_recommend" class="form-label">是否推荐:</label>
              <div class="clearfix">
                <div class="form-check form-check-inline">
                  <input type="radio" id="is_recommend" name="is_recommend" class="form-check-input" value="1" >
                  <label class="form-check-label" for="is_recommend">推荐</label>
                </div>
                <div class="form-check form-check-inline">
                  <input type="radio" id="is_recommend" name="is_recommend" class="form-check-input" value="0" checked>
                  <label class="form-check-label" for="is_recommend">不推荐</label>
                </div>
              </div>
            </div>

            <div class="mb-3 col-md-12">
              <label for="status" class="form-label">状态:</label>
              <div class="clearfix">
                <div class="form-check form-check-inline">
                  <input type="radio" id="status" name="status" class="form-check-input" value="1" checked>
                  <label class="form-check-label" for="status">显示</label>
                </div>
                <div class="form-check form-check-inline">
                  <input type="radio" id="status" name="status" class="form-check-input" value="0">
                  <label class="form-check-label" for="status">不显示</label>
                </div>
              </div>
            </div>
            <input type="hidden" id="jump_url" value="{$action}">
            <div class="mb-3 col-md-12">
              <button type="button" class="btn btn-primary ajax-post"target-form="add-form">确 定</button>
              <button type="button" class="btn btn-default" id="close_layer_open">返 回</button>
            </div>
          </form>
          
        </div>
      </div>
    </div>
        
  </div>
  
</div>
{include file="public/script"}

<script type="text/javascript" src="/static/admin/js/webuploader/webuploader.js"></script>
<link rel="stylesheet" type="text/css" href="/static/admin/summernote/summernote-lite.min.css">
<script type="text/javascript" src="/static/admin/summernote/summernote-lite.min.js"></script>
<script type="text/javascript">
uploader = WebUploader.create({
    auto: true,
    server: '/admin/common/uploadImage',
    pick: {
        id:'.filePicker',
        //是否开启多个文件选择能力
        multiple:false,
    },
    formData: {
         _token:''
    },
    fileVal:'file',
})
//上传成功时的回调方法
uploader.on('uploadSuccess',function (file,res) {
    if(res.code == 200)
    {
        $('.file_path_value').val(res.data);
        $('.show_upload_file').attr('src', res.data);
    }else{
        showNotify(res.msg, 'danger', 1000, 'mdi mdi-information-outline', 'top', 'right');
    }
})
uploader.on( 'uploadError', function( file ) {
    showNotify('上传文件失败', 'danger', 1000, 'mdi mdi-information-outline', 'top', 'right');
});
</script>
<script type="text/javascript">
  $('#content').summernote({
    placeholder: '文章内容',
    tabsize: 1,
    height: 480,
    toolbar: [
      ['style', ['style']],
      ['font', ['bold', 'underline', 'clear']],
      ['color', ['color']],
      ['para', ['ul', 'ol', 'paragraph']],
      ['table', ['table']],
      ['insert',['picture','link','table','hr']],
      ['view', ['fullscreen', 'codeview', 'help']]
    ]
  });

</script>
<script type="text/javascript">
  $('.ajax-post').click(function (){
    var text = $('#content').summernote('code');
    var isEmpty = $('#content').summernote('isEmpty');
    if(isEmpty)
    {
        showNotify('请填入内容', 'danger', 1500, 'mdi mdi-emoticon-angry', 'top', 'right');
        return false;
    }

    formData = $('#common_form').serialize();

    $.post('/admin/article/add',{form_data:formData, rich_text:text},function(res){
        if(res.code == 200)
        {
            showNotify(res.msg, 'success', 1500, 'mdi mdi-emoticon-happy', 'top', 'right');
            setTimeout(function() {
            
                window.parent.location.reload();  var index = parent.layer.getFrameIndex(window.name);  parent.layer.close(index);
      
            }, 1500);
        }else{
            showNotify(res.msg, 'danger', 1500, 'mdi mdi-emoticon-angry', 'top', 'right');
        } 
    })
    
})
</script>
</body>
</html>